﻿using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using OpenAdmin.Core.DbContextLocators;

namespace OpenAdmin.Core.Models;

/// <summary>
/// 分类表
/// </summary>
[Table("Categorys")]
public class Category : EntityBase<MallDbContextLocator>, IEntityTypeConfigure<Category>, IEntityTypeSeedDataConfigure<Category>
{
    /// <summary>
    /// 分类名称
    /// </summary>
    public string Name { get; set; }
    /// <summary>
    /// 父级Id
    /// </summary>
    public int ParentId { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    public int Sort { get; set; }

    public void Configure(EntityTypeBuilder<Category> entityBuilder)
    {
        entityBuilder.Property(p => p.Name).HasMaxLength(64);
    }

    public IEnumerable<Category> HasData(DbContext dbContext)
    {
        return new List<Category>()
        {
            new Category { Id = 1, Name = "流行", ParentId = 0, Sort = 1, CreateTime = DateTime.Now },
            new Category { Id = 2, Name = "新款", ParentId = 0, Sort = 2, CreateTime = DateTime.Now },
            new Category { Id = 3, Name = "精选", ParentId = 0, Sort = 3, CreateTime = DateTime.Now },
        };
    }
}
